var Sequelize = require('sequelize');

//连接数据库及信息
var sequelize = new Sequelize(
    'meet_schedule', // 数据库名
    'root',   // 用户名
    'wefire2017!',   // 用户密码
    {
        'dialect': 'mysql',  // 数据库使用mysql
        'host': '47.52.246.71', // 数据库服务器ip192.168.1.32
        'port': 3306,        // 数据库服务器端口
        'define': {
            // 字段以下划线（_）来分割（默认是驼峰命名风格）
            'underscored': true
        }
    }
);


//会员
var memberModule = require('./member')(sequelize);

//会议
var meetModule = require('./meet')(sequelize);

//会议厅
var buildModule = require('./build')(sequelize);

//会议专题
var meetSubjectModule = require('./meet_subject')(sequelize);

//会议日程
var meetScheduleModule = require('./meet_schedule')(sequelize);

//主持与讲者
var speakHostModule = require('./speak_host')(sequelize);

//会议预约
var meetOrderModule = require('./meet_order')(sequelize);

//会议和人员关系表
var meetSpeakModule = require('./meet_speak')(sequelize);




//建立关系
//会议人员与会员建立关系
buildModule.belongsTo(meetModule,{foreignKey:'meetId',targetKey:'id'});
meetModule.hasMany(buildModule,{foreignKey:'meetId'});

meetScheduleModule.belongsTo(buildModule,{foreignKey:'buildId',targetKey:'id'});
buildModule.hasMany(meetScheduleModule,{foreignKey:'buildId'});

meetScheduleModule.belongsTo(meetSubjectModule,{foreignKey:'meetSubjectId',targetKey:'id'});
meetSubjectModule.hasMany(meetScheduleModule,{foreignKey:'meetSubjectId'});

meetScheduleModule.belongsTo(speakHostModule,{foreignKey:'speakHostId',targetKey:'id'});
speakHostModule.hasMany(meetScheduleModule,{foreignKey:'speakHostId'});

meetSubjectModule.belongsTo(buildModule,{foreignKey:'buildId',targetKey:'id'});
buildModule.hasMany(meetSubjectModule,{foreignKey:'buildId'});

meetOrderModule.belongsTo(meetScheduleModule,{foreignKey:'meetScheduleId',targetKey:'id'});
meetScheduleModule.hasMany(meetOrderModule,{foreignKey:'meetScheduleId'});

meetSpeakModule.belongsTo(speakHostModule,{foreignKey:'speakHostId',targetKey:'id'});
speakHostModule.hasMany(meetSpeakModule,{foreignKey:'speakHostId'});



var db = function(){
    this.sequelize = sequelize;
    this.memberModule = memberModule;
    this.meetModule = meetModule;
    this.buildModule = buildModule;
    this.meetSubjectModule = meetSubjectModule;
    this.meetScheduleModule = meetScheduleModule;
    this.speakHostModule = speakHostModule;
    this.meetOrderModule = meetOrderModule;
    this.meetSpeakModule = meetSpeakModule;
}  

module.exports = db; 